//
// C++ Implementation: MaxScoreDiscardStrategy
//
// Description:
//
//
// Author: Kristina Bennett <kls93@caip.rutgers.edu>, (C) 2008
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "strategies/MaxScoreDiscardStrategy.h"
#include "Query.h"

#if DEBUG_LEVEL > 0
#include <iostream>
using std::cout;
using std::endl;
#endif

/**
 * Uncertainty increases with the number of tied cards
 */ 
int MaxScoreDiscardStrategy::getDecisionCertainty() {
    return (100 / numTiedCards);
}

int MaxScoreDiscardStrategy::pickDiscard(CCardStack* hand, bool lastCardPicked, const GameState* gameState) {

  int maxScore;
  CCardStack choiceCards;
  vector<int> choiceIndices;

  vector<int> scores = Query::FourCardValues(*hand);
  if (lastCardPicked)
    scores.pop_back();

  // Find the max score from allowable discards
  maxScore = Query::maxValue(scores);
#if DEBUG_LEVEL > 2
  cout << "The max score is " << maxScore << ".\n";
  cout.flush();
#endif
  for (unsigned int i=0; i<scores.size(); i++) {
    if (scores[i] == maxScore) {
#if DEBUG_LEVEL > 2
      cout << "\t" << hand->GetCard(i).Initials() << " is a choice.\n";
      cout.flush();
#endif
      choiceIndices.push_back(i);
      choiceCards.Push(hand->GetCard(i));
    }
  }
  numTiedCards = choiceCards.size();
  int choice = Query::minValueIndex(choiceCards);

  return choiceIndices[choice];

}
